package com.limingru.iteratorDesign;

public class NameRepository implements Container {
    private String[] names = new String[] {"张三", "李四", "赵六", "刘七"};

    @Override
    public Iterator iterator() {
        return new NameIterator();
    }

    class NameIterator implements Iterator {
        int index = 0;

        @Override
        public boolean hasNext() {
            if (index < names.length) {
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            String name = names[index];
            index++;
            return name;
        }
    }
}
